<layout name="master"/>
</div>
<!--导航结束-->
<div class="clear"></div>

</div>
<!--头部结束-->
<script>
    $(function () {
        area.init('area');
        //默认选中效果
        area.selected('山西', '临汾', '尧都区');

    })
</script>
<!--中间开始-->
<div id="content">
    <div class="ordercontent main" style="height:auto">
        <div class="orderleft">
            <div class="ordertitle">
                <h1>个人中心</h1>
                <ul>
                    <li><a href="{:u('index')}">我的订单<span>&gt;</span></a></li>
                    <li><a href="{:u('manageAddress')}">管理地址<span>&gt;</span></a></li>
                </ul>
            </div>
        </div>
        <div class="orderright">
            <div class="orderlist">
                <h2>管理地址</h2>
                <div class="body-center" style="width:100%;margin:0">
                    <div class="center-content">
                        <!--地址选择开始-->
                        <div class="content-address">
                            <div class="addressList">
                                <foreach name="addressData" item="v" key="k">
                                    <div class="consignee-item">
                                        <span class="radio-img <?php if($v['status']){ echo 'pitchOn';} ?> "></span>
                                        <label class="radio">
                                            <input type="radio" name="adress" class="radio-select" value=""/><span
                                                class="e-name">{$v['ac_name']}</span>，<span
                                                class="city">{$v['city']} </span><span
                                                class="city-particular">{$v['p_address']}</span>，<span
                                                class="codeNumber">{$v['mobile']}</span>
                                            <input type="hidden" class="postCode" name="postCode"
                                                   value="{$v['postcode']}">
                                        </label>
                                        <span class="compile"><a class="del_address" href="javascript:;"
                                                                 aid="{$v['aid']}">删除</a></span>
                                        <span class="compile"><a class="copyreader" href="javascript:;"
                                                                 aid="{$v['aid']}">编辑&nbsp;&nbsp;</a></span>

                                    </div>
                                </foreach>
                            </div>


                            <!--添加新地址-->

                            <div class="consignee-item new-ress addAdress_span">
                                <span class="radio-img pitchOn"></span>
                                <label for="adress3" class="radio"><input type="radio" name="adress" id="adress3"
                                                                          class="radio-select"
                                                                          value=""/>使用新地址</label>
                            </div>
                            <!--添加地址按钮-->
                            <a href="javascript:;" class="new-address"></a>
                            <!--添加地址框-->
                            <div class="add-address new addAddress_form">
                                <form action="" method="post">
                                    <div class="s-name">
                                        <h3 class="style"><b>*</b>收货人姓名</h3>
                                        <input type="text" class="public" name="ac_name" placeholder="收货人姓名" value=""/>
                                    </div>
                                    <div class="address-s">
                                        <h3 class="style"><b>*</b>地址</h3>

                                        <!--城市联动-->
                                        <select name="city[]" id="area1"></select>
                                        <select name="city[]" id="area2"></select>
                                        <select name="city[]" id="area3"></select>
                                        <!--<input type="text" name="name" id="name" placeholder="收货人姓名" value="" />-->
                                        <textarea name="p_address" placeholder="路名或街道地址，门牌号 " id="particular" rows=""
                                                  cols=""></textarea>
                                    </div>

                                    <div class="postcode">
                                        <h3 class="style"><b>&nbsp;</b>邮政编码</h3>
                                        <input type="text" class="public" name="postcode" id="postcode"
                                               placeholder="6位邮政编码" value=""/>
                                    </div>
                                    <div class="shouji">
                                        <h3 class="style"><b>*</b>手机号码 </h3>
                                        <input type="tel" class="public" name="mobile" id="shouji" placeholder="11位手机号码"
                                               value=""/>
                                    </div>
                                    <div class="btn-group">
                                        <input type="submit" class="btn" id="btn-bao" value="保存"/>
                                        <a href="javascript:;" class="btn-qu btn">取消</a>
                                    </div>
                                </form>
                                <script>
                                    $(function () {
                                        $('.new form').submit(function () {
                                            var data = $(this).serialize();
                                            $.post("{:u('ajaxAddAddress')}", data, function (res) {
                                                if (res) {
                                                    $('.addAdress_span,.addAddress_form').hide();
                                                    $('.new-address').show();
                                                    var html = '<div class="consignee-item">' +
                                                        '<span class="radio-img pitchOn"></span>' +
                                                        '<label class="radio">' +
                                                        '<input type="radio" name="adress" class="radio-select" value=""/><span class="e-name">' + res.ac_name + '</span>，<span class="city">' + res.city + '</span><span class="city-particular">' + res.p_address + '</span>，<span class="codeNumber">' + res.mobile + '</span>' +
                                                        '</label>' +
                                                        '<input type="hidden" class="postCode" name="postCode" value="' + res.postcode + '">' +
                                                        '<span class="compile"><a class="del_address" href="javascript:;" aid="' + res.aid + '">删除</a></span>' +
                                                        '<span class="compile"><a class="copyreader" href="javascript:;" aid="' + res.aid + '">编辑&nbsp;&nbsp;</a></span>' +
                                                        '</div>';
                                                    $(".addressList .consignee-item .radio-img").removeClass('pitchOn');
                                                    $('.addressList').append(html);
                                                } else {
                                                    layer.msg('请填入完整信息！');
                                                }
                                            }, 'json');
                                            return false;
                                        })
                                    })
                                </script>
                            </div>

                            <!--添加新地址结束-->
                            <!--编辑开始-->
                            <div class="add-address edit">
                                <form action="" method="post">
                                    <div class="s-name">
                                        <h3 class="style"><b>*</b>收货人姓名</h3>
                                        <input type="text" class="public" name="ac_name" id="name" placeholder="收货人姓名"
                                               value=""/>
                                    </div>
                                    <div class="address-s">
                                        <h3 class="style"><b>*</b>地址</h3>
                                        <!--城市联动-->
                                        <select name="city[]" id="area_1"></select>
                                        <select name="city[]" id="area_2"></select>
                                        <select name="city[]" id="area_3"></select>
                                        <!--<input type="text" name="name" id="name" placeholder="收货人姓名" value="" />-->
                                        <textarea name="p_address" placeholder="路名或街道地址，门牌号 " id="particular" rows=""
                                                  cols=""></textarea>
                                    </div>

                                    <div class="postcode">
                                        <h3 class="style"><b>&nbsp;</b>邮政编码</h3>
                                        <input type="text" class="public" name="postcode" id="postcode"
                                               placeholder="6位邮政编码" value=""/>
                                    </div>
                                    <div class="shouji">
                                        <h3 class="style"><b>*</b>手机号码 </h3>
                                        <input type="text" class="public" name="mobile" id="shouji"
                                               placeholder="11位手机号码" value=""/>
                                    </div>
                                    <div class="btn-group">
                                        <input type="hidden" id="aid" name="aid" value="1">
                                        <input type="submit" class="btn" id="btn-bao" value="保存"/>
                                        <a href="javascript:;" class="btn-qu btn">取消</a>
                                    </div>

                                </form>
                            </div>
                            <!--编辑结束-->
                            <script>
                                $(function () {
                                    $('.edit form').submit(function () {
                                        var data = $(this).serialize();
                                        console.log(data);
                                        $.post("{:u('ajaxEditAddress')}", data, function (res) {
                                            if (res) {
                                                var html = '<div class="consignee-item">' +
                                                    '<span class="radio-img pitchOn"></span>' +
                                                    '<label class="radio">' +
                                                    '<input type="radio" name="adress"  class="radio-select" value=""/><span class="e-name">' + res.ac_name + '</span>，<span class="city">' + res.city + '</span><span class="city-particular">' + res.p_address + '</span>，<span class="codeNumber">' + res.mobile + '</span>' +
                                                    '</label>' +
                                                    '<input type="hidden" class="postCode" name="postCode" value="' + res.postcode + '">' +
                                                    '<span class="compile"><a class="del_address" href="javascript:;" aid="' + res.aid + '">删除</a></span>' +
                                                    '<span class="compile"><a class="copyreader" href="javascript:;" aid="' + res.aid + '">编辑&nbsp;&nbsp;</a></span>' +
                                                    '</div>';
                                                $('.consignee-item .copyreader[aid=' + res.aid + ']').parents('.consignee-item').replaceWith(html);
                    //                              让其他兄弟元素的背景图消失
                                                $('.consignee-item').find('.radio-img').removeClass('pitchOn');
                //                                选中所编辑的地址
                                                $('.consignee-item .copyreader[aid=' + res.aid + ']').parents('.consignee-item').find('.radio-img').addClass('pitchOn');
                                                $('.edit').hide();
                                            } else {
                                                layer.msg('请填入完整信息！');
                                            }
                                        }, 'json');
                                        return false;
                                    })
                                })
                            </script>
                        </div>
                        <!--地址选择结束-->
                    </div>
                </div>


            </div>
        </div>
        <div style="clear:both"></div>
    </div>


</div>
</div>
<!--中间结束-->